package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.ScenicDetail;
import cn.wolfcode.luowowo.article.domain.ScenicTag;
import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.mapper.ScenicDetailMapper;
import cn.wolfcode.luowowo.article.query.ScenicDetailQuery;
import cn.wolfcode.luowowo.article.service.IScenicDetailService;
import cn.wolfcode.luowowo.cache.keys.RedisKeys;
import cn.wolfcode.luowowo.cache.vo.ScenicStatisVO;
import cn.wolfcode.luowowo.cache.vo.TravelStatisVO;
import cn.wolfcode.luowowo.common.util.BeanUtil;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScenicDetailServiceImpl  implements IScenicDetailService {
    @Autowired
    private ScenicDetailMapper scenicDetailMapper;

    @Override
    public List<ScenicDetail> listHot() {
        List<String> list = new ArrayList<>();
        List<ScenicDetail> details = scenicDetailMapper.selectHot(ScenicDetail.STATE_HOT);
        for (ScenicDetail detail : details) {
            String[] split = detail.getCoverUrl().split(",");
            for (String s : split) {
                list.add(s);
            }
            detail.setCoverUrls(list);
        }
        return details;
    }


    @Override
    public List<ScenicDetail> listByDestIdAndTagId(Long destId, Long tagId) {
        return scenicDetailMapper.selectByDestIdAndTagId(destId,tagId);
    }

    @Override
    public ScenicDetail getDetail(Long id) {
        List<String> list = new ArrayList<>();
        ScenicDetail detail = scenicDetailMapper.selectByPrimaryKey(id);
        String[] split = detail.getCoverUrl().split(",");
        for (String s : split) {
            list.add(s);
        }
        detail.setCoverUrls(list);
        return detail;
    }

    @Override
    public PageInfo query(ScenicDetailQuery qo) {
        List<String> list = new ArrayList<>();
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ScenicDetail> details = scenicDetailMapper.selectForList(qo);
        for (ScenicDetail detail : details) {
            String[] split = detail.getCoverUrl().split(",");
            for (String s : split) {
                list.add(s);
            }
            detail.setCoverUrls(list);
        }
        return new PageInfo(details);
    }

    @Override
    public List<ScenicDetail> listbyDest() {
        List<String> list = new ArrayList<>();
        List<ScenicDetail> details = scenicDetailMapper.selectAll();
        for (ScenicDetail detail : details) {
            String[] split = detail.getCoverUrl().split(",");
            for (String s : split) {
                list.add(s);
            }
            detail.setCoverUrls(list);
        }
        return details;
    }

    @Override
    public List<ScenicDetail> listInside(Long[] refIds) {
        List<String> list = new ArrayList<>();
        List<ScenicDetail> details = scenicDetailMapper.selectByRefIds(refIds);
        for (ScenicDetail detail : details) {
            String[] split = detail.getCoverUrl().split(",");
            for (String s : split) {
                list.add(s);
            }
            detail.setCoverUrls(list);
        }
        return details;
    }


}
